package com.woniu.smart.controller;

import com.woniu.smart.entity.Staffs;
import com.woniu.smart.service.StaffsService;
import com.woniu.smart.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**

 * @Description 企业员工表的信息记录
 * @date 2022/10/21 14:12
 * @author mei
 **/

@RestController
@RequestMapping("staffs")
public class StaffsController {

    @Autowired
    private StaffsService staffsService;

    /**
     * 查询全部人员信息
     * @return list集合
     */
    @GetMapping("")
    public Result selectAll(){
        List<Staffs> contractList = staffsService.selectStaffsAll();
        return Result.ok().data("contractList",contractList);
    }

    /**
     *  根据id查询人员信息
     * @date 2022/10/20 21:40
     * @param id
     * @return com.woniu.smart.util.Result
     **/
    @GetMapping("{id}")
    public Result queryStaffsByid(@PathVariable("id") Long id){
        Staffs staffs = staffsService.selectByPrimaryKey(id);
        return Result.ok().data("staffs",staffs);
    }

    /**
     *  新增企业人员信息
     * @date 2022/10/20 21:40
     * @param staffs
     * @author meibing
     * @return com.woniu.smart.util.Result
     **/
    @PostMapping("")
    public Result insertStaffsOne(@RequestBody Staffs staffs){

        int relist = staffsService.insertSelective(staffs);
        return Result.ok().data("Staffs",relist);
    }

    /**
     *
     * @date 2022/10/20 21:40
     * @param staffs
     * @author meibing
     * @return com.woniu.smart.util.Result
     **/
    @PostMapping("updateStaffsOne")
    public Result updateStaffsOne(@RequestBody Staffs staffs){
        System.out.println(staffs.toString());
        int ints = staffsService.updateByPrimaryKeySelective(staffs);
        if(ints>0){
            return Result.ok().data("ints",ints);
        }else{
            return Result.error("人员信息表更新失败");
        }

    }
    /**
     * @Description 批量删除企业员工信息
     * @author meibing
     * @date  14:41:09
     * @return: com.woniu.smart.util.Result
     */
    @DeleteMapping("deleteAll")
    public Result deleteStaffsAllByList(@RequestParam("staffseids") List<Integer> staffseids ){
        int i = staffsService.deleteByStaffsPrimaryKeyList(staffseids);
        if (i>0){
            return Result.ok();
        }else {
            return Result.error();
        }
    }


}
